#include "left_turn_predicate.h"

double MAXX = -1E50;

bool in_edge(point &e_b, point &e_e, point &p)
{
	if ((p.x > e_b.x && p.x > e_e.x) || 
		 (p.x < e_b.x && p.x < e_e.x) || 
		 (p.y > e_b.y && p.y > e_e.y) || 
		 (p.y < e_b.y && p.y < e_e.y))
		 return false;
	return true;
}

int in_polygon(std::vector<point> &polygon, point &p, point &p_end)
{
	int is_num = 0;
	for (size_t i = 1; i < polygon.size(); i++)
	{
		if (left_turn_predicate(polygon[i - 1], polygon[i], p) == 0 &&
			in_edge(polygon[i - 1], polygon[i], p))
			return 0;
		if (intersect(polygon[i - 1], polygon[i], p, p_end))
			is_num++;
	}
	if (is_num % 2 == 1)
		return 1;
	return -1;
}